home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_apache2.idb / usr / freeware / apache2 / include / apr_general.h.z / apr_general.h
C/C++ Source or Header  |  2002-07-08  |  9KB  |  276 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  */
  54.  
  55. #ifndef APR_GENERAL_H
  56. #define APR_GENERAL_H
  57. /**
  58.  * @file apr_general.h
  59.  * @brief APR Misc routines
  60.  */
  61. #include "apr.h"
  62. #include "apr_pools.h"
  63. #include "apr_errno.h"
  64.  
  65. #if APR_HAVE_SIGNAL_H
  66. #include <signal.h>
  67. #endif
  68.  
  69. #ifdef __cplusplus
  70. extern "C" {
  71. #endif /* __cplusplus */
  72.  
  73. /**
  74.  * @defgroup APR_Misc Misc routines
  75.  * @ingroup APR
  76.  * @{
  77.  */
  78.  
  79. /** FALSE */
  80. #ifndef FALSE
  81. #define FALSE 0
  82. #endif
  83. /** TRUE */
  84. #ifndef TRUE
  85. #define TRUE (!FALSE)
  86. #endif
  87.  
  88. /**
  89.  * The Win32 call WaitForMultipleObjects will only allow you to wait for 
  90.  * a maximum of MAXIMUM_WAIT_OBJECTS (current 64).  Since the threading 
  91.  * model in the multithreaded version of apache wants to use this call, 
  92.  * we are restricted to a maximum of 64 threads.  
  93.  * @see wait_for_many_objects  for a way to increase this size
  94.  */
  95.  
  96. #ifndef MAXIMUM_WAIT_OBJECTS
  97. #define MAXIMUM_WAIT_OBJECTS 64
  98. #endif
  99.  
  100. /** a space */
  101. #define APR_ASCII_BLANK  '\040'
  102. /** a carrige return */
  103. #define APR_ASCII_CR     '\015'
  104. /** a line feed */
  105. #define APR_ASCII_LF     '\012'
  106. /** a tab */
  107. #define APR_ASCII_TAB    '\011'
  108.  
  109. typedef int               apr_signum_t;
  110.  
  111. /**
  112.  * Finding offsets of elements within structures.
  113.  * Taken from the X code... they've sweated portability of this stuff
  114.  * so we don't have to.  Sigh...
  115.  * @param p_type pointer type name
  116.  * @param field  data field within the structure pointed to
  117.  * @return offset
  118.  */
  119.  
  120. #if defined(CRAY) || (defined(__arm) && !defined(LINUX))
  121. #ifdef __STDC__
  122. #define APR_OFFSET(p_type,field) _Offsetof(p_type,field)
  123. #else
  124. #ifdef CRAY2
  125. #define APR_OFFSET(p_type,field) \
  126.         (sizeof(int)*((unsigned int)&(((p_type)NULL)->field)))
  127.  
  128. #else /* !CRAY2 */
  129.  
  130. #define APR_OFFSET(p_type,field) ((unsigned int)&(((p_type)NULL)->field))
  131.  
  132. #endif /* !CRAY2 */
  133. #endif /* __STDC__ */
  134. #else /* ! (CRAY || __arm) */
  135.  
  136. #define APR_OFFSET(p_type,field) \
  137.         ((long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
  138.  
  139. #endif /* !CRAY */
  140.  
  141. /**
  142.  * Finding offsets of elements within structures.
  143.  * @param s_type structure type name
  144.  * @param field  data field within the structure
  145.  * @return offset
  146.  */
  147. #ifdef offsetof
  148. #define APR_OFFSETOF(s_type,field) offsetof(s_type,field)
  149. #else
  150. #define APR_OFFSETOF(s_type,field) APR_OFFSET(s_type*,field)
  151. #endif
  152.  
  153. /** @deprecated @see APR_OFFSET */
  154. #define APR_XtOffset APR_OFFSET
  155.  
  156. /** @deprecated @see APR_OFFSETOF */
  157. #define APR_XtOffsetOf APR_OFFSETOF
  158.  
  159.  
  160. /**
  161.  * A couple of prototypes for functions in case some platform doesn't 
  162.  * have it
  163.  */
  164. #if (!APR_HAVE_STRCASECMP) && (APR_HAVE_STRICMP) 
  165. #define strcasecmp(s1, s2) stricmp(s1, s2)
  166. #elif (!APR_HAVE_STRCASECMP)
  167. int strcasecmp(const char *a, const char *b);
  168. #endif
  169.  
  170. #if (!APR_HAVE_STRNCASECMP) && (APR_HAVE_STRNICMP)
  171. #define strncasecmp(s1, s2, n) strnicmp(s1, s2, n)
  172. #elif (!APR_HAVE_STRNCASECMP)
  173. int strncasecmp(const char *a, const char *b, size_t n);
  174. #endif
  175.  
  176. /**
  177.  * Alignment macros
  178.  */
  179.  
  180. /* APR_ALIGN() is only to be used to align on a power of 2 boundary */
  181. #define APR_ALIGN(size, boundary) \
  182.     (((size) + ((boundary) - 1)) & ~((boundary) - 1))
  183.  
  184. #define APR_ALIGN_DEFAULT(size) APR_ALIGN(size, 8)
  185.  
  186.  
  187. /**
  188.  * String and memory functions
  189.  */
  190.  
  191. #define APR_STRINGIFY(n) APR_STRINGIFY_HELPER(n)
  192. #define APR_STRINGIFY_HELPER(n) #n
  193.  
  194. #if (!APR_HAVE_MEMMOVE)
  195. #define memmove(a,b,c) bcopy(b,a,c)
  196. #endif
  197.  
  198. #if (!APR_HAVE_MEMCHR)
  199. void *memchr(const void *s, int c, size_t n);
  200. #endif
  201.  
  202. /**
  203.  * Setup any APR internal data structures.  This MUST be the first function 
  204.  * called for any APR library.
  205.  * @deffunc apr_status_t apr_initialize(void)
  206.  * @remark See apr_app_initialize if this is an application, rather than
  207.  * a library consumer of apr.
  208.  */
  209. APR_DECLARE(apr_status_t) apr_initialize(void);
  210.  
  211. /**
  212.  * Set up an application with normalized argc, argv (and optionally env) in
  213.  * order to deal with platform-specific oddities, such as Win32 services,
  214.  * code pages and signals.  This must be the first function called for any
  215.  * APR program.
  216.  * @param argc Pointer to the argc that may be corrected
  217.  * @param argv Pointer to the argv that may be corrected
  218.  * @param env Pointer to the env that may be corrected, may be NULL
  219.  * @remark See apr_initialize if this is a library consumer of apr.
  220.  * Otherwise, this call is identical to apr_initialize, and must be closed
  221.  * with a call to apr_terminate at the end of program execution.
  222.  */
  223. APR_DECLARE(apr_status_t) apr_app_initialize(int *argc, 
  224.                                              char const * const * *argv, 
  225.                                              char const * const * *env);
  226.  
  227. /**
  228.  * Tear down any APR internal data structures which aren't torn down 
  229.  * automatically.
  230.  * @remark An APR program must call this function at termination once it 
  231.  *         has stopped using APR services.  The APR developers suggest using
  232.  *         atexit to ensure this is called.  When using APR from a language
  233.  *         other than C that has problems with the calling convention, use
  234.  *         apr_terminate2() instead.
  235.  */
  236. APR_DECLARE_NONSTD(void) apr_terminate(void);
  237.  
  238. /**
  239.  * Tear down any APR internal data structures which aren't torn down 
  240.  * automatically, same as apr_terminate
  241.  * @remark An APR program must call either the apr_terminate or apr_terminate2 
  242.  *         function once it it has finished using APR services.  The APR 
  243.  *         developers suggest using atexit(apr_terminate) to ensure this is done.
  244.  *         apr_terminate2 exists to allow non-c language apps to tear down apr, 
  245.  *         while apr_terminate is recommended from c language applications.
  246.  */
  247. APR_DECLARE(void) apr_terminate2(void);
  248.  
  249. /** @} */
  250.  
  251. /**
  252.  * @defgroup APR_Random Random Functions
  253.  * @ingroup APR
  254.  * @{
  255.  */
  256.  
  257. #if APR_HAS_RANDOM
  258.  
  259. /* TODO: I'm not sure this is the best place to put this prototype...*/
  260. /**
  261.  * Generate a string of random bytes.
  262.  * @param buf Random bytes go here
  263.  * @param length size of the buffer
  264.  */
  265. APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char * buf, 
  266.                                                     int length);
  267.  
  268. #endif
  269. /** @} */
  270.  
  271. #ifdef __cplusplus
  272. }
  273. #endif
  274.  
  275. #endif  /* ! APR_GENERAL_H */
  276.